package com.ts.main.mini.config;

import com.wechat.pay.java.core.Config;
import com.wechat.pay.java.core.RSAPublicKeyConfig;
import com.wechat.pay.java.core.notification.NotificationConfig;
import com.wechat.pay.java.core.notification.RSAPublicKeyNotificationConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

/**
 * @Author:lk
 * @Date: 2025/5/28  22:11
 */
@Component
public class JsapiConfig {

    @Value("${wechat.merchantId}")
    private String merchantId;

    @Value("${wechat.privateKeyPath}")
    public String privateKeyPath;

    @Value("${wechat.publicKeyPath}")
    public String publicKeyPath;

    @Value("${wechat.publicKeyId}")
    private String publicKeyId;

    @Value("${wechat.merchantSerialNumber}")
    public String merchantSerialNumber;

    @Value("${wechat.apiV3Key}")
    private String apiV3Key;


    /**
     * 初始化商户信息
     *
     * @return
     */
    @Bean
    public Config initConfig() {
        // 使用本地公私钥
        Config config =
                new RSAPublicKeyConfig.Builder()
                        .merchantId(merchantId)
                        .privateKeyFromPath(privateKeyPath)
                        .publicKeyFromPath(publicKeyPath)
                        .publicKeyId(publicKeyId)
                        .merchantSerialNumber(merchantSerialNumber)
                        .apiV3Key(apiV3Key)
                        .build();
        return config;
    }

    @Bean
    public NotificationConfig initNotificationConfig() {
        NotificationConfig config =
                new RSAPublicKeyNotificationConfig.Builder()
                        .publicKeyFromPath(publicKeyPath)
                        .publicKeyId(publicKeyId)
                        .apiV3Key(apiV3Key)
                        .build();
        return config;
    }

//    @Bean
//    public Config initRSAConfig() {
//        Config config =
//                new RSAConfig.Builder()
//                        .merchantId(merchantId)
//                        .privateKeyFromPath(privateKeyPath)
//                        .merchantSerialNumber(merchantSerialNumber)
//                        .wechatPayCertificatesFromPath(publicKeyPath)
//                        .build();
//        return config;
//    }

}
